<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = mysql_real_escape_string($_SESSION['user']);
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2 && $row['type'] != 3)
	header("Location: home.php");
?>
<!doctype html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0">
    <link rel="icon" href="http://www.veteranboosters.com/wp-content/uploads/2014/04/favicon4.png" type="image/x-icon"/>
    <link rel="shortcut icon" href="http://www.veteranboosters.com/wp-content/uploads/2014/04/favicon4.png" type="image/x-icon"/>
  <!-- Always force latest IE rendering engine or request Chrome Frame -->
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">

  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,800">

  <!-- Use title if it's in the page YAML frontmatter -->
  <title>ELO Edge Order Tracking</title>


  <!--[if lt IE 9]>
  <script src="../../javascripts/vendor/html5shiv.js" type="text/javascript"></script>
  <script src="../../javascripts/vendor/excanvas.js" type="text/javascript"></script>
  <![endif]-->
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.css" />
<link rel="stylesheet" href="css/fullcalendar.css" />
<link rel="stylesheet" href="css/jquery.jscrollpane.css" />	
<link rel="stylesheet" href="css/unicorn.css" />
  <link href="stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="javascripts/application.js" type="text/javascript"></script>
</head>

<?php
	include("top.php");
?>

  <div class="container-fluid padded">
    <div class="row-fluid">

      <!-- Breadcrumb line -->

      <div id="breadcrumb">
			  <a href="#" title="Go to Home" class="tip-bottom"><i class="fa fa-home"></i> Home</a>
			<a href="#" >Members</a>
			<a href="#" class="current"> Search users  </a>
	</div>
    </div>
  </div>

  <div class="container-fluid padded">
  <div class="row-fluid">
   <div class="col-lg-12">
      <div class="box">
         <div class="box-header">
            <span class="title">Search</span>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
                     <td>Email</td>
					 <td>IP</td>
					 <td>Actions</td>
                  </tr>
               </thead>
               <tbody>
			   <tr><td><input type = "text" id = "email" /></td>
			   <td><input type = "text" id = "ip" /></td>
			   <td><input type="submit" class="btn btn-success btn-xs" value="Search" onclick = "fetch_user()"></td>
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>
  <div class="row-fluid">
   <div class="col-lg-12">
      <div class="box">
         <div class="box-header">
            <span class="title">Results</span>
         </div>
         <div class="box-content">
            <table class="table table-normal">
               <thead>
                  <tr>
                     <td>ID</td>
					 <td>Last IP</td>
                     <td>Username</td>
                     <td>Paypal</td>
					 <td>Summoner</td>
					 <td>Actions</td>
                  </tr>
               </thead>
               <tbody id = "users">
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>

</div>
<script>
function fetch_user ()
{
	var ajaxHandler = new XMLHttpRequest();

	ajaxHandler.onreadystatechange = function ()
	{
		if(ajaxHandler.readyState == 4)
		{
			document.getElementById("users").innerHTML = ajaxHandler.responseText;
		}
	}

	var form = new FormData();

	form.append("ip", document.getElementById("ip").value);
	form.append("email", document.getElementById("email").value);

	ajaxHandler.open("POST", "fetch-users.php");
	ajaxHandler.send(form);
}

function ban (id)
{
	var reason = prompt("Please enter ban reason for user "+id+": ", "");

	if(reason != null)
	{
		window.location = "http://eloedge.com/track/ban.php?id="+id+"&ban_reason="+reason;
	}
}
</script>
</div>
<?php
	include("bottom.php");
?>